package com.ease.platform.auditlog.support;

import com.ease.common.util.JsonUtil;
import com.ease.model.system.type.AuditLogSeverityType;
import com.ease.platform.auditlog.vo.AuditLogObject;

public abstract class AuditLogSupport {

	public static void logDebug(Object target) {
		log(AuditLogSeverityType.DEBUG, JsonUtil.marshal(target));
	}

	public static void logDebug(String message) {
		log(AuditLogSeverityType.DEBUG, message);
	}

	public static void logWarn(String message) {
		log(AuditLogSeverityType.WARN, message);
	}

	public static void logError(String message) {
		log(AuditLogSeverityType.ERROR, message);
	}

	private static void log(AuditLogSeverityType auditLogSeverityType, String message) {
		if (null != AuditLogContext.getAuditLogContext()) {
			if (null != message) {
				AuditLogObject auditLogObject = new AuditLogObject();
				auditLogObject.setAuditLogSeverityType(auditLogSeverityType);
				auditLogObject.setMessage(message);
				//
				AuditLogContext.getAuditLogContext().addAuditLogObject(auditLogObject);
			}
		}
	}
}
